package com.liuyk.commonlib.web;

import com.liuyk.commonlib.web.bridge.BaseBridge;
import com.liuyk.commonlib.web.bridge.CommonBridge;

import java.util.HashMap;
import java.util.Map;

/**
 * method管理
 * 方法动态增加，删除等
 * <p>
 * Created by liuyakui on 2020/7/6
 */
public class BridgeManager {
    private final Map<String, BaseBridge> jsHandlers;

    private BridgeManager() {
        jsHandlers = new HashMap<>();

        //默认
        addBridge(new CommonBridge());
    }

    public static BridgeManager getInstance() {
        return Inner.INSTANCE;
    }

    public void addBridge(BaseBridge baseBridge) {
        jsHandlers.put(baseBridge.getBridgeName(), baseBridge);
    }

    public BaseBridge removeBridge(String key) {
        return jsHandlers.remove(key);
    }

    public BaseBridge getBridge(String key) {
        return jsHandlers.get(key);
    }

    public Map<String, BaseBridge> getJsHandlers() {
        return jsHandlers;
    }

    private static class Inner {
        private static final BridgeManager INSTANCE = new BridgeManager();
    }

}
